<template>
<van-picker
  title="标题"
  show-toolbar
  :columns="columns"
  @confirm="onConfirm"
  @cancel="$emit('close')"
  @change="onChange"
  :default-index="value"
/>
</template>

<script>
import { updateUserName } from '@/api/user'
export default {
  components: {},
  props: {
    value: {
      type: [Number, String],
      required: true
    }
  },
  data () {
    return {
      columns: ['女', '男']
    }
  },
  computed: {},
  watch: {},
  created () {

  },
  mounted () {},
  methods: {
    async onConfirm (value, index) {
      try {
        await updateUserName({
          gender: index
        })
        this.$emit('input', this.gender)
        this.$emit('close')
        this.$toast('更新成功')
      } catch (err) {
        console.log(err)
      }
    },
    onChange (picker, value, index) {
      this.$toast(`当前值：${value}, 当前索引：${index}`)
    },
    onCancel () {
      this.$toast('取消')
    }
  }
}
</script>

<style scoped>

</style>
